#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main (int argc, char const* argv[])
{
    int m, n, i, j, time, t, current_cnt, cnt;
    char name[16], buf[16], *pos, score[16], tname[16];
    int current_cnts[1024], times[1024];
    char names[1024][16];

    scanf("%d %d", &n, &m);

    cnt = 0;
    while (scanf("%s", name) != EOF) {
        current_cnt = 0;
        time = 0;
        for (i = 0; i < n; i++) {
            scanf("%s", buf);
            pos = strchr(buf, '(');
            if (pos != NULL) {
                snprintf(score, pos - buf + 1, "%s", buf);
                t = atoi(score);
                snprintf(score, buf + strlen(buf) - 1 - pos, "%s", pos+1);
                t += atoi(score) * m;
            } else {
                t = atoi(buf);
            }

            if (t > 0) {
                current_cnt++;
                time += t;
            }
        }

        strcpy(names[cnt], name);
        current_cnts[cnt] = current_cnt;
        times[cnt] = time;

        cnt++;
    }

    for (i = 0; i < cnt-1; i++) {
        for (j = i+1; j < cnt; j++) {
            if (current_cnts[i] < current_cnts[j] || 
                    (current_cnts[i] == current_cnts[j] && times[i] > times[j])) {
                strcpy(tname, names[i]);
                strcpy(names[i], names[j]);
                strcpy(names[j], tname);

                t = current_cnts[i];
                current_cnts[i] = current_cnts[j];
                current_cnts[j] = t;

                t = times[i];
                times[i] = times[j];
                times[j] = t;
            }
        }
    }

    for (i = 0; i < cnt; i++) {
        printf("%-10s %2d %4d\n", names[i], current_cnts[i], times[i]);
    }

    return 0;
}
